package AliDiepPR.ANN;

import java.util.Random;

import AliDiepPR.ANN.Layer;

public class Network {

	Layer[] layer;

	public Layer Layer(int i) {
		return layer[i];
	}

	int numLayer;

	public int NumLayer(int n, boolean set) {
		if (set)
			this.numLayer = n;
		return numLayer;
	}

	public Network() {

	}

	public Network(int num, int[] arrUnit) {

		this.numLayer = num;

		layer = new Layer[this.numLayer];

		for (int i = 0; i < this.numLayer; i++)
			layer[i] = new Layer(arrUnit[i]);
	}
	
	public void Randomize(Random rand) {

		for (int lay = 0; lay < numLayer - 1; lay++) {

			int next = this.Layer(lay + 1).numUnit;

			// randomize threshold
			for (int i = 0; i < next; i++)
				this.Layer(lay + 1).Unit(i).Randomize(rand);

			// randomize weight
			this.Layer(lay).RandomizeWeight(next, rand);
		}
	}

	public void InitNetwork(int numLayer, int[] info, float[][] threshold,
			float[][][] wei) {

		this.numLayer = numLayer;

		layer = new Layer[numLayer];
		for (int lay = 0; lay < numLayer; lay++)
			layer[lay] = new Layer(info[lay]);

		for (int lay = 1; lay < numLayer; lay++) {
			int pre = layer[lay].numUnit;
			for (int i = 0; i < pre; i++)
				this.Layer(lay).Unit(i).Threshold(threshold[lay][i], true);
		}

		for (int lay = 0; lay < numLayer - 1; lay++)
			layer[lay].initWeight(info[lay + 1], wei[lay]);
	}
}
